要求使用StringBuilder来完成打印由7,8,9三个数组成的三位数
**分析以下需求,并用代码实现:
(1),要求该三位数中任意两位数字不能相同;
(2)打印格式最后的三位数字以空格分隔,如789 798 879 897 978 987。**
实现方法如下:
package homework;
import java.text.SimpleDateFormat;
import java.util.Date;
import static java.util.Arrays.sort;
/**
* @program: day01
* @description: 三位数组成
* @Date: 2018/8/1 11:10
* @author: myy
*/
public class Problem11 {
public static void main(String[] args) {
StringBuilder s1 = new StringBuilder("78978");
int[] ints = new int[6];
int count = 0;
for(int i = 0; i < 3; i ++) {
StringBuilder s2 = new StringBuilder(s1.substring(i, (i + 3)).toString());
ints[count ++] = Integer.parseInt(s2.toString());
ints[count ++] = Integer.parseInt(s2.reverse().toString());
//System.out.println(s2.toString());
//System.out.println(s2.reverse().toString());
}
sort(ints);
for (int num : ints) {
System.out.print(num+" ");
}
}
}